package com.ruoyi.web.controller.report;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.domain.report.vo.StudentReportLisReqVo;
import com.ruoyi.system.domain.report.vo.StudentReportListResVo;
import com.ruoyi.system.domain.report.vo.StudentReportListResVo2;
import com.ruoyi.system.domain.report.vo.StudentReportVo;
import com.ruoyi.system.service.ITabPtdetailService;
import com.ruoyi.system.service.report.IStudentService;
import com.ruoyi.system.service.report.ITeacherService;
import io.swagger.annotations.ApiOperation;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/report")
@CrossOrigin
public class StudentReportController extends BaseController {
    @Autowired
    private ITabPtdetailService tabPtdetailService;

    @Autowired
    private IStudentService iStudentService;

    @Autowired
    private TokenService tokenService;


    /**
     * 检查报告列表
     */
    @PostMapping("/ReportByList")
    public TableDataInfo randomQuestion(TabPtdetail tabPtdetail) {
        startPage();
        List<TabPtdetail> list = tabPtdetailService.selectTabPtdetailList(tabPtdetail);
        return getDataTable(list);
    }


    /*`*
     * 分页条件查询学生报告列表
     * @paramp
     * @param studentReportLisReqVo
     * @return
     */
    @PostMapping("/studentReportListPage")
    public TableDataInfo patientInfoList(@RequestBody StudentReportLisReqVo studentReportLisReqVo) {

        String userName = tokenService.getLoginUser(ServletUtils.getRequest()).getUsername();
        startPage();
        try {
            studentReportLisReqVo.setUserName(userName);
            List<StudentReportListResVo> patientInfoList = iStudentService.getPatientInfoList(studentReportLisReqVo);
            return getDataTable(patientInfoList);
        } catch (Exception e) {
            throw new GlobalException("查询失败请联系管理员");
        }

    }


    /**
     * 查询学生报告
     *
     * @param reportId
     * @return
     */
    @GetMapping("/studentReportInfo/{reportId}")
    public AjaxResult patientInfo(@PathVariable String reportId) {
        return AjaxResult.success(iStudentService.getPatientInfo(reportId));
    }

    /**
     * 更新
     *
     * @param studentReportVo
     * @return
     */
    @PostMapping("/update/report")
    public AjaxResult updateReport(@RequestBody StudentReportVo studentReportVo) {
        try {
            iStudentService.updateReport(studentReportVo);
        } catch (Exception e) {
            throw new GlobalException("更新失败,教师已批改的内容无法在保存!");
        }
        return AjaxResult.success("更新成功");
    }


    /**
     * 保存
     *
     * @param studentReportVo
     * @return
     */
    @PostMapping("/save/report")
    public AjaxResult saveReport(@RequestBody StudentReportVo studentReportVo) {
        try {
            iStudentService.saveReport(studentReportVo);
        } catch (Exception e) {
            throw new GlobalException("保存失败,教师已批改的内容无法在保存!");
        }
        return AjaxResult.success("保存成功");
    }


    /**
     * 获取患者随访记录
     *
     * @param reportId
     * @return
     */
    @GetMapping("/getSurvey/{reportId}")
    @ApiOperation(value = "获取随访记录")
    public AjaxResult getSurvey(@PathVariable String reportId) {
        return AjaxResult.success(iStudentService.getSurvey(reportId));
    }


    /**
     * 获取病史
     *
     * @param reportId
     * @return
     */
    @GetMapping("/getBgReadyTxt/{reportId}")
    public AjaxResult getBgReadyTxt(@PathVariable String reportId) {
        return AjaxResult.success(iStudentService.getBgReadyTxt(reportId));
    }

    /**
     * 获取检查所见
     *
     * @param reportId
     * @return
     */
    @GetMapping("/getCheckSee/{reportId}")
    public AjaxResult getCheckSee(@PathVariable String reportId) {
        return AjaxResult.success(iStudentService.getCheckSee(reportId));
    }


    /**
     * 获取检查意见
     *
     * @param reportId
     * @return
     */
    @GetMapping("/getCheckOpinion/{reportId}")
    public AjaxResult getCheckOpinion(@PathVariable String reportId) {
        return AjaxResult.success(iStudentService.getCheckOpinion(reportId));
    }


    /**
     * 获取比较数据源
     *
     * @param reportId
     * @return
     */
    @GetMapping("/getCompareData/{reportId}")
    public AjaxResult getCompareData(@PathVariable String reportId) {
        return AjaxResult.success(iStudentService.getCompareData(reportId));
    }


    /**
     * 更详细的分页条件查询学生报告列表
     *
     * @param studentReportLisReqVo
     * @return
     */
    @PostMapping("/studentReportListPagePro")
    public TableDataInfo patientInfoListPro(@RequestBody StudentReportLisReqVo studentReportLisReqVo) {
        String userName = tokenService.getLoginUser(ServletUtils.getRequest()).getUsername();
        startPage();
        try {
            studentReportLisReqVo.setUserName(userName);
            List<StudentReportListResVo2> patientInfoList = iStudentService.getPatientInfoListPro(studentReportLisReqVo);
            return getDataTable(patientInfoList);
        } catch (Exception e) {
            throw new GlobalException("查询失败请联系管理员");
        }
    }


    @Autowired
    private ITeacherService iTeacherService;

    /**
     * 报告医生
     * @param bgDto
     * @return
     */
    // 报告提取
    @PostMapping("/student/ExtractReport")
    public AjaxResult ExtractReport(@RequestBody BgDto bgDto) {

        return iStudentService.ExtractReport(bgDto);
    }

    // 撤销报告提取
    @PostMapping("/student/returnPtdStatus")
    public AjaxResult returnPtdStatus(@RequestBody BgDto bgDto) {
        return iTeacherService.returnPtdStatus(bgDto);
    }

    // 获取所有报告医生
    @GetMapping("/student/AllBgDoctor")
    public AjaxResult AllBgDoctor() {
        return AjaxResult.success(iTeacherService.AllBgDoctor());
    }

    // 提交审核
    @PostMapping("/student/submitCommited")
    public AjaxResult submitCommited(@RequestBody BgDto bgDto) {
        return iTeacherService.submitCommited(bgDto);
    }

    // 撤销提交审核
    @PostMapping("/student/backCommited")
    public AjaxResult backCommited(@RequestBody BgDto bgDto) {
        return iTeacherService.backCommited(bgDto);
    }


    /**
     * 审核医生
     * @param bgDto
     * @return
     */
    // 审核提取
    @PostMapping("/student/ExtractSHReport")
    public AjaxResult ExtractSHReport(@RequestBody BgDto bgDto){
        return iTeacherService.ExtractSHReport(bgDto);
    }

    // 撤销审核提取
    @PostMapping("/student/returnPtdStatus2")
    public AjaxResult returnPtdStatus2(@RequestBody BgDto bgDto){
        return iTeacherService.returnPtdStatus2(bgDto);
    }

    // 审核通过
    @PostMapping("/student/ReportApproved")
    public AjaxResult ReportApproved(@RequestBody BgDto bgDto){
        return iTeacherService.ReportApproved(bgDto);
    }

    // 获取所有审核医生
    @GetMapping("/student/AllShDoctor")
    public AjaxResult AllShDoctor(){
        return AjaxResult.success(iTeacherService.AllShDoctor());
    }

    // 转审
    @PostMapping("/student/changeShDoctor")
    public AjaxResult changeShDoctor(@RequestBody BgDto bgDto){
        return iTeacherService.changeShDoctor(bgDto);
    }

    // 提交复审
    @PostMapping("/student/submitCommited2")
    public AjaxResult submitCommited2(@RequestBody BgDto bgDto){
        return iTeacherService.submitCommited2(bgDto);
    }

    // 撤销提交复审
    @PostMapping("/student/backCommited2")
    public AjaxResult backCommited2(@RequestBody BgDto bgDto){
        return iTeacherService.backCommited2(bgDto);
    }

    /**
     * 复审医生
     * @param bgDto
     * @return
     */
    // 复审提取
    @PostMapping("/student/changePtdStatus3")
    public AjaxResult changePtdStatus3(@RequestBody BgDto bgDto) {
        return iTeacherService.changePtdStatus3(bgDto);
    }


    // 撤销复审提取
    @PostMapping("/student/returnPtdStatus3")
    public AjaxResult returnPtdStatus3(@RequestBody BgDto bgDto) {
        return iTeacherService.returnPtdStatus3(bgDto);
    }

    // 复审通过
    @PostMapping("/student/reportApproved2")
    public AjaxResult reportApproved2(@RequestBody BgDto bgDto) {
        return iTeacherService.reportApproved2(bgDto);
    }

    // 获取所有复审医生
    @GetMapping("/student/AllFsDoctor")
    public AjaxResult AllFsDoctor() {
        return AjaxResult.success(iTeacherService.AllFsDoctor());
    }

    // 转复审
    @PostMapping("/student/changeShDoctor2")
    public AjaxResult changeShDoctor2(@RequestBody BgDto bgDto) {
        return iTeacherService.changeShDoctor2(bgDto);
    }

    //获取当前报告状态以及对应医生和时间
    @GetMapping("/student/timeAndDoctor/{id}")
    public AjaxResult timeAndDoctor(@PathVariable String id) {
        return AjaxResult.success(iTeacherService.timeAndDoctor(id));
    }
}
